package com.jxgk.application.conroller;

import com.jxgk.application.pojo.User;
import com.jxgk.application.service.UserService;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;


@RequestMapping("user")
@org.springframework.stereotype.Controller
public class Controller {
    @Autowired
    public UserService userService;


    @RequestMapping("/{page}")
    public String showPage(@PathVariable String page) {
        return "add";
    }

    @RequestMapping("addUser")
    public String addUser(User user){
        userService.addUser(user);
        return "add";
    }

    @RequestMapping("listUser")
   public String listUser(Model model){
        List<User> list=   userService.listUser();
     model.addAttribute("list",list);
       return "list";
    }

    @RequestMapping("login")
    public String login(Model model, User user, HttpSession session){
        User us = userService.login(user);
        if (us!=null){
            session.setAttribute("us",us);
            return "redirect:/user/listUser";
        }
        return "login";
    }

}
